package com.mt.system.service.model;

import java.util.List;
import java.util.Map;

import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import com.github.pagehelper.PageHelper;
import com.mt.common.PagerInfo;
import com.mt.common.ServiceResult;
import com.mt.system.entity.CityEntity;
import com.mt.system.mapper.CityEntityMapper;

@Component
public class CityServiceModel {
    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CityServiceModel.class);

    @Autowired
    private CityEntityMapper cityEntityMapper;

    public ServiceResult<List<CityEntity>> selectList(Map<String, Object> params, PagerInfo<?> pagerInfo) {
        Assert.notNull(this.cityEntityMapper, "Property 'cityEntityMapper' is required.");
        ServiceResult<List<CityEntity>> result = new ServiceResult<List<CityEntity>>();
        try {
            if (pagerInfo != null) {
                PageHelper.startPage(pagerInfo.getPageIndex(), pagerInfo.getPageSize());
            }

            result.setResult(this.cityEntityMapper.selectList(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[SupplierImageServiceImpl][findList]：query findList occur exception", e);
        }
        return result;
    }

    public ServiceResult<CityEntity> selectInfo(Map<String, Object> params) {
        Assert.notNull(this.cityEntityMapper, "Property 'cityEntityMapper' is required.");
        ServiceResult<CityEntity> result = new ServiceResult<CityEntity>();
        try {
            result.setResult(this.cityEntityMapper.selectByPrimaryKey(params));
        } catch (Exception e) {
            result.setSuccess(false);
            result.setMessage("Unknown error!");
            LOGGER.error("[CityServiceModel][selectInfo]：query selectInfo occur exception", e);
        }
        return result;
    }
}
